/**
 * 
 */
package com.msh.platform.elm.common.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * 集合排序
 * 
 * @author shamee-loop
 * 
 */
@Slf4j
public class SortUtils {

	/**
	 * 按英文首字母排序
	 * 
	 * @param arrayToSort
	 */
	private static String sortStringArray(List<String> arrayList) {

		log.info("字符型数组排序,排序前:");
		String result = "";
		for (int i = 0; i < arrayList.size(); i++) {
			System.out.println(arrayList.get(i) + ",");
		}
		log.info("排序后:");

		// 调用数组的静态排序方法sort,且不区分大小写
		// Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
		Collections.sort(arrayList);

		for (int i = 0; i < arrayList.size(); i++) {
			log.info(arrayList.get(i) + ",");
			result += arrayList.get(i);
		}
		log.info("组装接口签名数据：" + result);
		return result;// 组装接口签名用数据
	}

	/**
	 * 参数封装，获取排序数据
	 * 
	 * @param map
	 * @return
	 */
	public static String sortMap(Map<String, Object> map) {
		if (map != null && !map.isEmpty()) {
			List<String> list = new ArrayList<String>();
			for (Map.Entry<String, Object> entry : map.entrySet()) {
				if (entry.getValue() != null
						&& !StringUtils.isBlank(entry.getValue().toString()) 
						&& !entry.getValue().toString().trim().equals("null")) {
					list.add(entry.getKey() + entry.getValue());
				}
			}
			return sortStringArray(list);
		}
		return null;
	}

	public static void main(String[] args) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("Oscar", "11");
		param.put("OscarId", "22");
		param.put("Charlie", "www");
		param.put("David", "qwe12");
		String str = sortMap(param);
		log.info(str);
	}

}
